package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.DictData;
import com.ruoyi.car.service.IDictDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务字典管理Controller
 * 
 * @author yby
 * @date 2025-09-02
 */
@RestController
@RequestMapping("/car/dict")
public class DictDataController extends BaseController
{
    @Autowired
    private IDictDataService dictDataService;

    /**
     * 查询业务字典管理列表
     */
    @PreAuthorize("@ss.hasPermi('car:dict:list')")
    @GetMapping("/list")
    public TableDataInfo list(DictData dictData)
    {
        startPage();
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        return getDataTable(list);
    }

    /**
     * 导出业务字典管理列表
     */
    @PreAuthorize("@ss.hasPermi('car:dict:export')")
    @Log(title = "业务字典管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DictData dictData)
    {
        List<DictData> list = dictDataService.selectDictDataList(dictData);
        ExcelUtil<DictData> util = new ExcelUtil<DictData>(DictData.class);
        util.exportExcel(response, list, "业务字典管理数据");
    }

    /**
     * 获取业务字典管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:dict:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dictDataService.selectDictDataById(id));
    }

    /**
     * 新增业务字典管理
     */
    @PreAuthorize("@ss.hasPermi('car:dict:add')")
    @Log(title = "业务字典管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DictData dictData)
    {
        return toAjax(dictDataService.insertDictData(dictData));
    }

    /**
     * 修改业务字典管理
     */
    @PreAuthorize("@ss.hasPermi('car:dict:edit')")
    @Log(title = "业务字典管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DictData dictData)
    {
        return toAjax(dictDataService.updateDictData(dictData));
    }

    /**
     * 删除业务字典管理
     */
    @PreAuthorize("@ss.hasPermi('car:dict:remove')")
    @Log(title = "业务字典管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dictDataService.deleteDictDataByIds(ids));
    }

    /**
     * 根据字典类型查询字典数据
     */
    @GetMapping("/type/{dictType}")
    public AjaxResult getDictByType(@PathVariable String dictType)
    {
        List<DictData> list = dictDataService.selectDictDataByType(dictType);
        return success(list);
    }
}
